<?php


$prefixList = [
    'collections\\map',
    'collections\\set',
    'collections\\compare',
    'util',
    'system\\in',
    'leetcode'
];

foreach ($prefixList as $prefix) {
    spl_autoload_register(function($clazz) use($prefix) {
        $len = strlen($prefix);
        if (0 != strncmp($prefix, $clazz, $len)) {
            return;
        }
        $baseDir = dirname(__FILE__) . DIRECTORY_SEPARATOR.
            str_replace('\\', DIRECTORY_SEPARATOR, $prefix);
        $relativeClass = substr($clazz, $len);

        $file = $baseDir.str_replace('\\', DIRECTORY_SEPARATOR, $relativeClass).'.php';
        if (!file_exists($file)) {
            throw new \InvalidArgumentException($file.' does not exists');
        }
        require $file;
    });
}
